/**
 * 2017年3月2日
 */
package pojo.weichatlab.figure;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;

import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;




/**
 * @author Alex
 *
 */
public abstract class AbstractChart {
	public String title;
	public String subTitle;
	public static ObjectMapper om ;
	protected static String FIELDNAME = "chart";
	
	public static <T> T fromRequest(HttpServletRequest req,Class<T> clzz){
		String chartStr = (String)req.getParameter(FIELDNAME);
		try {
			return om.readValue(chartStr, clzz);
		} catch (JsonParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch (JsonMappingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return null;
		}		
	}
}
